# 目标检测

import cv2
 # 读取图像和目标分类器
image = cv2.imread('./static/2.png')
cascade = cv2.CascadeClassifier('./module/haarcascade_frontalface_default.xml')
 # 将图像转换为灰度图像
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
 # 进行目标检测
targets = cascade.detectMultiScale(gray_image, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30))
 # 在图像上绘制检测到的目标框
for (x, y, w, h) in targets:
    cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2)
 # 显示原始图像和检测结果
cv2.imshow('Original Image', image)
cv2.waitKey(0)
cv2.destroyAllWindows()
